﻿using System;
using System.Collections.Generic;
using System.Text;

namespace masterCard
{
    public enum BidDenomination { C = 1, D, H, S, NT, Pass, Doubled, ReDoubled,NULL };
    
    public class Bid
    {

        private BidDenomination m_eBidDenomination;
        private int m_nBidLevel;

        public Bid()
        {
            m_eBidDenomination = BidDenomination.NULL;
            m_nBidLevel = 0;
        }

        public Bid(string bid)
        {
            string[] tok = bid.Split('_');
            if (tok.Length == 2)
            {
                m_eBidDenomination = getBidType(tok[1]);
                m_nBidLevel = getBidQuantity(tok[0]);
            }
            else
            {
                m_eBidDenomination = getBidType(bid);
                m_nBidLevel = 0;
            }

        }
        public BidDenomination BidDenomination
        {
            get { return m_eBidDenomination; }
            set { m_eBidDenomination = BidDenomination; }
        }
        public int BidLevel
        {
            get { return m_nBidLevel; }
            set
            {
                if (BidLevel <= 7)
                {
                    m_nBidLevel = BidLevel;
                }
            }
        }
        public static bool operator > (Bid lhs,Bid rhs)
        {
            //if (lhs.m_eBidDenomination >= BidDenomination.Pass)
            //{
            //    return true;
            //}
            if (lhs.m_nBidLevel > rhs.m_nBidLevel)
            {
                return true;
            }
            else if (lhs.m_nBidLevel == rhs.m_nBidLevel)
            {
                return (lhs.m_eBidDenomination > rhs.m_eBidDenomination);
            }
            return false;
        }
        public static bool operator <(Bid lhs, Bid rhs)
        {
            if (lhs.m_nBidLevel < rhs.m_nBidLevel)
            {
                return true;
            }
            else if (lhs.m_nBidLevel == rhs.m_nBidLevel)
            {
                return (lhs.m_eBidDenomination < rhs.m_eBidDenomination);
            }
            return false;
        }
        private int getBidQuantity(string p)
        {
            return int.Parse(p);
        }

        private BidDenomination getBidType(string p)
        {
            BidDenomination temp = BidDenomination.Pass;
            foreach (BidDenomination bt in BidDenomination.GetValues(typeof(BidDenomination)))
            {
                if (bt.ToString() == p)
                {
                    temp = bt;
                }
            }
            return temp;
        }
       

        internal static string GetBidButtonText(int nBidQuantity, BidDenomination bt)
        {
            String Symbol = "";
            switch (bt)
            {
                case BidDenomination.C:                    
                    Symbol = "♣";
                    break;
                case BidDenomination.D:                    
                    Symbol = "♦";
                    break;
                case BidDenomination.H:                    
                    Symbol = "♥";
                    break;
                case BidDenomination.S:                    
                    Symbol = "♠";
                    break;
                case BidDenomination.NT:                    
                    Symbol = "NT";
                    break;
                case BidDenomination.NULL:
                    Symbol = "-";
                    break;
                case BidDenomination.Pass:
                    Symbol = "PASS";
                    break;
                case BidDenomination.Doubled:
                    Symbol = "D";
                    break;
                case BidDenomination.ReDoubled:
                    Symbol = "RD";
                    break;
            }
            if (nBidQuantity > 0)
            {
                return nBidQuantity.ToString() + Symbol;                
            }
            else
            {
                return Symbol;
            }
            
            
           
        }
        internal static object GetBidButtonTag(int nBidQuantity, BidDenomination bt)
        {           
            if (nBidQuantity > 0)
            {
                return nBidQuantity.ToString() + "_" + bt.ToString();
            }
            else
            {
                return bt.ToString();
            }            
        }
    }
}


